package com.kingl.common.core.util;

/**
 * Create by Administrator on 2020/5/18/018
 */
public class StaticResultJson<T> {
    private int code;
    private String msg;
    private T data;

    public StaticResultJson() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //构造成功的方法
    public static<T> StaticResultJson<T> ok(T data){
        return generalResult(200,"成功",data);
    }
    //构造业务异常
    public static<T> StaticResultJson<T> fail(){
        return generalResult(203,"业务异常",null);
    }
    //系统异常
    public static<T> StaticResultJson<T> error(){
        return generalResult(500,"系统异常,请联系管理员",null);
    }

    //统一的构造成功和返回的方法
    public static<T> StaticResultJson<T> generalResult(int code,String msg,T data){
        StaticResultJson<T> resultJson = new StaticResultJson<T>();
        resultJson.setCode(code);
        resultJson.setMsg(msg);
        resultJson.setData(data);
        return resultJson;
    }
}
